﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace Gaiocorp.SLViewer.ImageMapServer.PrintTemplates
{
    public partial class GenPrintTemplate : System.Web.UI.Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            string strPaperSizeOrientation = Request.QueryString["pso"];
            imgMap.ImageUrl = Session["PRINTIMAGE"].ToString();
            this.imgLegend.ImageUrl = Session["PRINTLEGIMAGE"].ToString();
            switch (strPaperSizeOrientation)
            {
                case "A4P":
                    cssPrint.Href = "css/ms_printA4Portait.css";
                    break;
                case "A4L":
                    cssPrint.Href = "css/ms_printA4Landscape.css";
                    break;
                case "A3P":
                    cssPrint.Href = "css/ms_printA3Portait.css";
                    break;
                case "A3L":
                    cssPrint.Href = "css/ms_printA3Landscape.css";
                    break;
            }

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Page.Title = Resources.IMX.PrintPage;
            string strMapTitle = Request.QueryString["title"];
            lblTitle.Text = strMapTitle;
            lblScale2.Text = Session["PRINTSCALE"].ToString();
            string crlf = "\r\n";
            //Open info file for reading
            string fnFooter = Server.MapPath("mapfooter.txt");

            //Get a StreamReader class that can be used to read the file
            StreamReader objStreamReader = File.OpenText(fnFooter);
            //Read the entire file into a string
            string contents = objStreamReader.ReadToEnd();

            //Replace carraige returns with <br>s
            this.lblInfo.Text = contents.Replace(crlf, "<br>");

            objStreamReader.Close();
            //Session["PRINTIMAGE"] = null;
            //Session["PRINTSCALE"] = null;
            //Session["PRINTLEGIMAGE"] = null;

        }
    }
}
